package org.fujene.communicate.hash;

/**
 * It generates hash.
 * 
 * @author fujisaka_yusuke
 */
public final class VirtualContentHash{
	private static int division;
	
	public static void setDivision(int div) {
		division = div;
	}
	
	public static long getTermHash(String str){
		long val = str.hashCode();
		val ^= val << 32;
		val ^= val >> 1;
		val ^= val << 39;
		
		return val;
	}

	public static long getContentHash(long docID){
		docID ^= 0x3307FFE45ABD407L;
		docID *= 7777;
		docID ^= docID << 32;
		docID ^= docID >> 1;
		docID ^= docID << 39;
		
		return docID;
	}
	
	public static long getNodeHash(String IPAddr, int index) {
		if(index >= division) throw new IndexOutOfBoundsException();
		long val = IPAddr.hashCode();
		val ^= val << 32;
		val ^= val >> 1;
		val ^= val << 17;
		
		return val;
	}
}
